﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace IISLogAnalyzer
{
    public class Statics
    {

        /// <summary>
        /// 获取显示列Sql
        /// </summary>
        /// <returns></returns>
        public static string GetSqlColumns()
        {
            string sql = "";
            sql += _date == 1 ? "[_date] as 日期," : "";
            sql += _time == 1 ? "[_time] as 时间," : "";
            sql += _ssitename == 1 ? "[_s-sitename] as 服务名称," : "";
            sql += _scomputername == 1 ? "[_s-computername] as 服务器名称," : "";
            sql += _sip == 1 ? "[_s-ip] as 服务器IP," : "";
            sql += _csmethod == 1 ? "[_cs-method] as 方法," : "";
            sql += _csuristem == 1 ? "[_cs-uri-stem] as URI资源," : "";
            sql += _csuriquery == 1 ? "[_cs-uri-query] as URI查询," : "";
            sql += _sport == 1 ? "[_s-port] as 服务器端口号," : "";
            sql += _csusername == 1 ? "[_cs-username] as 用户名," : "";
            sql += _cip == 1 ? "[_c-ip] as 客户端IP," : "";
            sql += _csversion == 1 ? "[_cs-version] as 协议版本," : "";
            sql += _csuseragent == 1 ? "[_cs(User-Agent)] as 用户代理," : "";
            sql += _csreferer == 1 ? "[_cs(Referer)] as 引用网站," : "";
            sql += _cshost == 1 ? "[_cs-host] as 主机," : "";
            sql += _scstatus == 1 ? "[_sc-status] as 协议状态," : "";
            sql += _scsubstatus == 1 ? "[_sc-substatus] as 协议子状态," : "";
            sql += _scwin32status == 1 ? "[_sc-win32-status] as Win32状态," : "";
            sql += _scbytes == 1 ? "[_sc-bytes] as 发送字节数," : "";
            sql += _csbytes == 1 ? "[_cs-bytes] as 接收字节数," : "";
            sql += _timetaken == 1 ? "[_time-taken] as 耗时（ms）," : "";
            sql += _cscookie == 1 ? "[_cs(Cookie)] as Cookie," : "";
            sql += _add_time == 1 ? "[_add_time] as 分析时间" : "";
            return sql;
        }

        /// <summary>
        /// 获取显示列Sql
        /// </summary>
        /// <returns></returns>
        public static string GetLikeSqlColumns(string key)
        {
            string sql = "";
            sql += _date == 1 ? "[_date] like '%" + key + "%' or " : "";
            sql += _time == 1 ? "[_time] like '%" + key + "%' or " : "";
            sql += _ssitename == 1 ? "[_s-sitename] like '%" + key + "%' or " : "";
            sql += _scomputername == 1 ? "[_s-computername] like '%" + key + "%' or " : "";
            sql += _sip == 1 ? "[_s-ip] like '%" + key + "%' or " : "";
            sql += _csmethod == 1 ? "[_cs-method] like '%" + key + "%' or " : "";
            sql += _csuristem == 1 ? "[_cs-uri-stem] like '%" + key + "%' or " : "";
            sql += _csuriquery == 1 ? "[_cs-uri-query] like '%" + key + "%' or " : "";
            sql += _sport == 1 ? "[_s-port] like '%" + key + "%' or " : "";
            sql += _csusername == 1 ? "[_cs-username] like '%" + key + "%' or " : "";
            sql += _cip == 1 ? "[_c-ip] like '%" + key + "%' or " : "";
            sql += _csversion == 1 ? "[_cs-version] like '%" + key + "%' or " : "";
            sql += _csuseragent == 1 ? "[_cs(User-Agent)] like '%" + key + "%' or " : "";
            sql += _csreferer == 1 ? "[_cs(Referer)] like '%" + key + "%' or " : "";
            sql += _cshost == 1 ? "[_cs-host] like '%" + key + "%' or " : "";
            sql += _scstatus == 1 ? "[_sc-status] like '%" + key + "%' or " : "";
            sql += _scsubstatus == 1 ? "[_sc-substatus] like '%" + key + "%' or " : "";
            sql += _scwin32status == 1 ? "[_sc-win32-status] like '%" + key + "%' or " : "";
            sql += _scbytes == 1 ? "[_sc-bytes] like '%" + key + "%' or " : "";
            sql += _csbytes == 1 ? "[_cs-bytes] like '%" + key + "%' or " : "";
            sql += _timetaken == 1 ? "[_time-taken] like '%" + key + "%' or " : "";
            sql += _cscookie == 1 ? "[_cs(Cookie)] like '%" + key + "%' or " : "";
            sql += _add_time == 1 ? "[_add_time] like '%" + key + "%' " : "";
            return sql;
        }

        public string columsSql { get; set; } = "[_date] as 日期,[_time] as 时间,[_s-sitename] as 服务名称,[_s-computername] as 服务器名称,[_s-ip] as 服务器IP,[_cs-method] as 方法,[_cs-uri-stem] as URI资源,[_cs-uri-query] as URI查询,[_s-port] as 服务器端口号,[_cs-username] as 用户名,[_c-ip] as 客户端IP,[_cs-version] as 协议版本,[_cs(User-Agent)] as 用户代理,[_cs(Referer)] as 引用网站,[_cs-host] as 主机,[_sc-status] as 协议状态,[_sc-substatus] as 协议子状态,[_sc-win32-status] as Win32状态,[_sc-bytes] as 发送字节数,[_cs-bytes] as 接收字节数,[_time-taken] as 耗时（ms）,[_cs(Cookie)] as Cookie,[_add_time] as 分析时间";

        /// <summary>
        /// 日期
        /// </summary>
        public static int _date { get; set; } = 1;
        /// <summary>
        /// 时间
        /// </summary>
        public static int _time { get; set; } = 1;
        /// <summary>
        /// 服务名称
        /// </summary>
        public static int _ssitename { get; set; } = 1;
        /// <summary>
        /// 服务器名称
        /// </summary>
        public static int _scomputername { get; set; } = 0;
        /// <summary>
        /// 服务器IP
        /// </summary>
        public static int _sip { get; set; } = 0;
        /// <summary>
        /// 方法
        /// </summary>
        public static int _csmethod { get; set; } = 1;
        /// <summary>
        /// URI资源
        /// </summary>
        public static int _csuristem { get; set; } = 1;
        /// <summary>
        /// URI查询
        /// </summary>
        public static int _csuriquery { get; set; } = 1;
        /// <summary>
        /// 服务器端口号
        /// </summary>
        public static int _sport { get; set; } = 0;
        /// <summary>
        /// 用户名
        /// </summary>
        public static int _csusername { get; set; } = 0;
        /// <summary>
        /// 客户端IP
        /// </summary>
        public static int _cip { get; set; } = 1;
        /// <summary>
        /// 协议版本
        /// </summary>
        public static int _csversion { get; set; } = 0;
        /// <summary>
        /// 用户代理
        /// </summary>
        public static int _csuseragent { get; set; } = 0;
        /// <summary>
        /// 引用网站
        /// </summary>
        public static int _csreferer { get; set; } = 0;
        /// <summary>
        /// 主机
        /// </summary>
        public static int _cshost { get; set; } = 0;
        /// <summary>
        /// 协议状态
        /// </summary>
        public static int _scstatus { get; set; } = 0;
        /// <summary>
        /// 协议子状态
        /// </summary>
        public static int _scsubstatus { get; set; } = 0;
        /// <summary>
        /// Win32状态
        /// </summary>
        public static int _scwin32status { get; set; } = 0;
        /// <summary>
        /// 发送字节数
        /// </summary>
        public static int _scbytes { get; set; } = 1;
        /// <summary>
        /// 接收字节数
        /// </summary>
        public static int _csbytes { get; set; } = 1;
        /// <summary>
        /// 耗时（ms）
        /// </summary>
        public static int _timetaken { get; set; } = 1;
        /// <summary>
        /// Cookie
        /// </summary>
        public static int _cscookie { get; set; } = 0;
        /// <summary>
        /// 分析时间
        /// </summary>
        public static int _add_time { get; set; } = 1;


    }
}
